package Offer2017;

/**
 * 数组中只出现1次的两个数字
 * Created by 雷文康 on 2018/1/6.
 */
public class Test40 {
    public static void main(String[] args) {
        int[] array={1,2,2,4,3,4,5,6,6,5};
        findNumOnce(array);
    }
    public static void findNumOnce(int[] array){
        if (array == null || array.length < 2){
            return;
        }
        int result = 0;
        for (int i = 0; i < array.length; i++) {
            result = result ^ array[i];
        }
        int index = 0;
        while ((result & 1) != 1){
            index++;
            result = result >> 1;
        }
        int num1 = 0;
        int num2 = 0;
        for (int i = 0; i < array.length; i++) {
            if (isBit1(array[i], index)){
                num1  = num1 ^ array[i];
            } else {
                num2 = num2 ^ array[i];
            }
        }
        System.out.println(num1);
        System.out.println(num2);
    }
    private static boolean isBit1(int num, int index){
        num = num >> index;
        return (num & 1) == 1;
    }
}
